package com.dianping.cat.alarm.receiver.transform;

import com.dianping.cat.alarm.receiver.entity.AlertConfig;
import com.dianping.cat.alarm.receiver.entity.Receiver;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;




public class DefaultDomMaker
  extends Object
  implements IMaker<Node>
{
  public AlertConfig buildAlertConfig(Node node) {
/*  16 */     String enable = getAttribute(node, "enable");

/*  18 */     AlertConfig alertConfig = new AlertConfig();

    if (enable != null) {
/*  21 */       alertConfig.setEnable((Boolean)convert(Boolean.class, enable, null));
    }

    return alertConfig;
  }



  public String buildDx(Node node) { return getText(node); }




/*  34 */   public String buildEmail(Node node) { return getText(node); }




/*  39 */   public String buildPhone(Node node) { return getText(node); }



  public Receiver buildReceiver(Node node) {
/*  44 */     String id = getAttribute(node, "id");
/*  45 */     String enable = getAttribute(node, "enable");

/*  47 */     Receiver receiver = new Receiver(id);

/*  49 */     if (enable != null) {
/*  50 */       receiver.setEnable((Boolean)convert(Boolean.class, enable, null));
    }

/*  53 */     return receiver;
  }



/*  58 */   public String buildWeixin(Node node) { return getText(node); }



  protected <T> T convert(Class<T> type, String value, T defaultValue) {
/*  63 */     if (value == null || value.length() == 0) {
/*  64 */       return defaultValue;
    }

/*  67 */     if (type == Boolean.class || type == boolean.class)
/*  68 */       return (T)Boolean.valueOf(value); 
/*  69 */     if (type == Integer.class || type == int.class)
/*  70 */       return (T)Integer.valueOf(value); 
/*  71 */     if (type == Long.class || type == long.class)
/*  72 */       return (T)Long.valueOf(value); 
/*  73 */     if (type == Short.class || type == short.class)
/*  74 */       return (T)Short.valueOf(value); 
/*  75 */     if (type == Float.class || type == float.class)
/*  76 */       return (T)Float.valueOf(value); 
/*  77 */     if (type == Double.class || type == double.class)
      return (T)Double.valueOf(value);
/*  79 */     if (type == Byte.class || type == byte.class)
/*  80 */       return (T)Byte.valueOf(value); 
/*  81 */     if (type == Character.class || type == char.class) {
/*  82 */       return (T)Character.valueOf(value.charAt(0));
    }
/*  84 */     return (T)value;
  }


  protected String getAttribute(Node node, String name) {
/*  89 */     Node attribute = node.getAttributes().getNamedItem(name);

/*  91 */     return (attribute == null) ? null : attribute.getNodeValue();
  }

  protected Node getChildTagNode(Node parent, String name) {
/*  95 */     NodeList children = parent.getChildNodes();
/*  96 */     int len = children.getLength();

/*  98 */     for (int i = 0; i < len; i++) {
/*  99 */       Node child = children.item(i);

/* 101 */       if (child.getNodeType() == 1 && 
/* 102 */         child.getNodeName().equals(name)) {
/* 103 */         return child;
      }
    }


/* 108 */     return null;
  }

  protected String getText(Node node) {
/* 112 */     if (node != null) {
/* 113 */       StringBuilder sb = new StringBuilder();
/* 114 */       NodeList children = node.getChildNodes();
/* 115 */       int len = children.getLength();

/* 117 */       for (int i = 0; i < len; i++) {
/* 118 */         Node child = children.item(i);

/* 120 */         if (child.getNodeType() == 3 || child.getNodeType() == 4) {
/* 121 */           sb.append(child.getNodeValue());
        }
      }

/* 125 */       if (sb.length() != 0) {
/* 126 */         return sb.toString();
      }
    }

/* 130 */     return null;
  }
}


/* Location:              /Users/hanfei/Documents/apache-tomcat-9.0.24/webapps/cat/WEB-INF/lib/cat-alarm-3.0.0.jar!/com/dianping/cat/alarm/receiver/transform/DefaultDomMaker.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.0.7
 */